import tkinter as tk
from tkinter import messagebox
from alg import Solution

def check_scramble():
    s1 = entry_s1.get()
    s2 = entry_s2.get()
    if len(s1) != len(s2):
        messagebox.showinfo("结果", "两个字符串长度必须相等！")
        return
    solution = Solution()
    result = solution.isScramble(s1, s2)
    messagebox.showinfo("结果", f"'{s2}' 是否是 '{s1}' 的扰乱字符串: {result}")

# 创建主窗口（其余UI代码保持不变）
root = tk.Tk()
root.title("字符串扰乱判断工具")
root.geometry("400x250")
root.resizable(False, False)

# 设置字体以确保中文显示正常
font_config = ("SimHei", 10)

# 创建输入框和标签
frame = tk.Frame(root, padx=20, pady=20)
frame.pack(fill=tk.BOTH, expand=True)

label_s1 = tk.Label(frame, text="原始字符串 s1:", font=font_config)
label_s1.pack(anchor=tk.W, pady=(0, 5))
entry_s1 = tk.Entry(frame, font=font_config, width=30)
entry_s1.pack(fill=tk.X, pady=(0, 15))

label_s2 = tk.Label(frame, text="待验证字符串 s2:", font=font_config)
label_s2.pack(anchor=tk.W, pady=(0, 5))
entry_s2 = tk.Entry(frame, font=font_config, width=30)
entry_s2.pack(fill=tk.X, pady=(0, 20))

# 创建按钮
button = tk.Button(frame, text="验证", command=check_scramble, 
                  font=font_config, bg="#4CAF50", fg="white",
                  height=1, width=10)
button.pack(pady=10)

# 示例说明
example_text = "示例: s1='great', s2='rgeat' → 结果: True"
label_example = tk.Label(frame, text=example_text, font=("SimHei", 9), fg="gray")
label_example.pack(side=tk.BOTTOM, pady=5)

# 运行主循环
root.mainloop()
